﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Me.Prettyprint.Cassandra.Utils;
using Me.Prettyprint.Hector.Api.Ddl;

namespace Me.Prettyprint.Cassandra.Serializers
{
    /// <summary>
    /// LongSerializer handles the conversion between big/little endian
    /// encoding to make sure it is cross platform safe.
    /// </summary>
    public class LongSerializer : AbstractSerializer<long>
    {
        public static LongSerializer Instance = new LongSerializer();

        public LongSerializer()
        {
        }
        public override ComparatorType GetComparatorType()
        {
            return ComparatorType.LONGTYPE;
        }
        override public ComparatorType ComparatorType
        {
            get
            {
                return ComparatorType.LONGTYPE;
            }
        }
        public override byte[] ToBytes(long obj)
        {
            return ConvertToBigEndianBytes(BitConverter.GetBytes(obj));
        }
        public override Utils.ByteBuffer ToByteBuffer(long obj)
        {
            return new ByteBuffer(ToBytes(obj));
        }
        public override long FromBytes(byte[] bytes)
        {
            return BitConverter.ToInt64(ConvertFromBigEndianBytes(bytes),0);
        }
        public override long FromByteBuffer(ByteBuffer buff)
        {
            return FromBytes(buff.GetBuffer());
        }
    }
}
